<template>

  <div style="width: 100%;height: 100vh;" class="view-box f-column-Wcenter">

    <div class="form-box ">
      <h3 style="border-bottom: #ccc 2px solid;padding-bottom: 30px;">资产抵押</h3>
      <div class="form ">
        <el-form ref="ruleForm1" :rules="rules1" :hide-required-asterisk="true" @submit.native.prevent
          @keyup.enter.native="stepsBtn('ruleForm1')" label-position="top" :model="ruleForm1">
          <div class="f-row-between" style="width: 600px;"><span>项目方公司名称：{{details.company}}</span> <span>对标商品名称：{{details2.assetName}}</span></div>
          <div class="f-row-Hcenter " style="width: 100%;margin-top: 20px;">
            <span>抵押资产名称：</span>
            <el-form-item prop="mortgage" style="margin-top: 20px;">
              <el-input style="margin-left: 20px;width: 100%;" v-model="ruleForm1.mortgage" maxlength="30"  placeholder="输入抵押资产名称"></el-input>
            </el-form-item>
          </div>
          <div class="f-row-between" style="width: 600px;margin-top: 20px;"><span>抵押资金计算</span></div>
          <div class="f-row-Hcenter " style="width: 100%;margin-top: 20px;margin-bottom: 20px;">
             
            <div class="f-row-Hcenter" style="margin-left: 20px;">
              <div class="f-row-Hcenter"><span>𝜠</span> </div>
              <span style="margin: 0 30px;">{{ruleForm1.benchmark}}</span>
            </div>
            <div class="f-row-Hcenter">
              <div class="f-row-Hcenter"><span>=</span></div>
              <el-input style="margin-left: 20px;" v-model="ruleFormE.compare_project_funds" maxlength="30" placeholder="𝛧(对标项目总资金)"></el-input>
            </div>
            <div class="f-row-Hcenter">
              <div class="f-row-Hcenter"><span>x</span></div>
              <el-input style="margin-left: 20px;" v-model="ruleFormE.safe_factor" maxlength="30" placeholder="𝛄(安全系数)"></el-input>
            </div>
            <el-button type="primary" plain style="margin-left: 30px;" @click="onAmountPriceE">执行运算</el-button>
          </div>
          <span style="color: #CCCCCC;">系数参考值： Κ=1.22， λ=1.35 具体参数值需确认而定</span>

          <el-form-item prop="mortgageGroup" style="margin-left: 20px;width: 100%;">
            <div class="f-row-between" style="width: 600px;margin-top: 20px;margin-bottom: 20px;"><span>抵押资产文件</span></div>
            <el-upload class="upload-demo upload-li-w50" :action="url+'/platform/attachmentFile/add'" :data="{ userId: userId,type:'ISTO_appraisal_report' }"
              :on-remove="deleteFile_mortgageGroup" :on-success="uploadFile_mortgageGroup" multiple :limit="5">
              <el-button size="small" type="primary">选择文件</el-button>
              <div slot="tip" class="el-upload__tip">
                请上传jpg / jpeg / png / pdf文件，文件大小不超过10MB;可上传多个文件
              </div>
            </el-upload>
          </el-form-item>
          <el-form-item prop="mortgageContractGroup" style="margin-left: 20px;width: 100%;">
            <div class="f-row-between" style="width: 600px;margin-top: 20px;margin-bottom: 20px;"><span>上传抵押合同</span></div>
            <el-upload class="upload-demo upload-li-w50" :action="url+'/platform/attachmentFile/add'" :data="{ userId: userId,type:'ISTO_appraisal_report' }"
              :on-remove="deleteFile_mortgageContractGroup" :on-success="uploadFile_mortgageContractGroup" multiple
              :limit="5">
              <el-button size="small" type="primary">选择文件</el-button>
              <div slot="tip" class="el-upload__tip">
                请上传jpg / jpeg / png / pdf文件，文件大小不超过10MB;可上传多个文件
              </div>
            </el-upload>
          </el-form-item>
        </el-form>
        <div>
          <el-button type="success" plain @click="stepsBtn(0)">驳回</el-button>
          <el-button type="success" plain @click="stepsBtn(1)">发布</el-button>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import serveApi from '@/api/serveApi.js'
  export default {
    name: "Authorization",
    data() {

      return {
        userInfo: '',
        userId: '',
        url: '',
        routeData: {},
        details: {},
        details2: {},
        query1: {
          id: 0,
          applyIstoId: 0
        },

        ruleFormE: {
          compare_project_funds: '', // *number(query) 对标项目总资金
          safe_factor: '' // *number(query) 安全系数
        },

        ruleForm1: {
          mortgage: '',
          benchmark: 0,
          mortgageGroup: '',
          mortgageContractGroup: ''

        },
        rules1: {
          mortgage: [{
            required: true,
            message: "请输入抵押资产",
            trigger: "blur"
          }],
          benchmark: [{
            required: true,
            message: "请运算抵押资金",
            trigger: "blur"
          },{ type: 'number', message: '资金必须为数字值'}],
          mortgageGroup: [{
            required: true,
            message: "请上传抵押资产文件",
            trigger: "blur"
          }],
          mortgageContractGroup: [{
            required: true,
            message: "请上传上传抵押合同",
            trigger: "blur"
          }],
        }
      }
    },
    mounted() {
      let that = this;

      that.url = process.env.VUE_APP_BASE_API;
      this.userId = this.$store.state.userInfo.id;
      this.routeData = this.$route.query
      this.getDetails();
      this.getDetails2();
    },
    methods: {
      getDetails() {
        this.query1.id = this.routeData.id;
        serveApi.applySto_id(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              this.details = res.data;
            }
          } else {
            this.$message.error(res.message);
          }
        });
      },
      getDetails2() {
        this.query1.applyIstoId = this.routeData.applyIstoId;
        serveApi.applyIsto_id(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              this.details2 = res.data;
            }
          } else {
            that.$message.error(res.message);
          }
        });
      },
      stepsBtn(e) {
        this.ruleForm1.id =21;// this.routeData.applyIstoId;
        if (e == 0) {
          this.ruleForm1.status = 6;
          serveApi.applyIsto_applyIsto(this.ruleForm1).then(res => {
            if (res.data) {
              this.$message.success('驳回成功');

            } else {
              this.$message.error(res.message);
            }
          });
        } else {


          if (this.ruleForm1.benchmark <= 0) {
            this.$message.error('请运算总资金');
            return
          }
          this.ruleForm1.status = 5;
		  this.ruleForm1.mortgageGroupId = JSON.stringify(this.ruleForm1.mortgageGroup);
		  this.ruleForm1.mortgageContractGroupId = JSON.stringify(this.ruleForm1.mortgageContractGroup);
          this.$refs.ruleForm1.validate(valid => {
            if (valid) {
             
              serveApi.applyIsto_applyIsto(this.ruleForm1).then(res => {
                if (res.data) {

                  this.$message.success('发布成功');

                } else {
                  this.$message.error(res.message);
                }
              });
            }
          })
        }

      },

      deleteFile_mortgageGroup(response, file, fileList) {
        let index = this.ruleForm1.mortgageGroup.findIndex(function(student) {
          return student.name == response.name;
        })
        this.ruleForm1.mortgageGroup.splice(index, 1);
      },
      uploadFile_mortgageGroup(response, file, fileList) {
        this.ruleForm1.mortgageGroup = this.ruleForm1.mortgageGroup || [];
        response.data.name = file.name;
        this.ruleForm1.mortgageGroup.push(response.data);
        this.$upload("ruleForm1", "mortgageGroup");
      },
      deleteFile_mortgageContractGroup(response, file, fileList) {
        let index = this.ruleForm1.mortgageContractGroup.findIndex(function(student) {
          return student.name == response.name;
        })
        this.ruleForm1.mortgageContractGroup.splice(index, 1);
      },
      uploadFile_mortgageContractGroup(response, file, fileList) {
        this.ruleForm1.mortgageContractGroup = this.ruleForm1.mortgageContractGroup || [];
        response.data.name = file.name;
        this.ruleForm1.mortgageContractGroup.push(response.data);
        this.$upload("ruleForm1", "mortgageContractGroup");
      },
      onAmountPriceE() {

        if (!this.ruleFormE.compare_project_funds) {
          this.$message.error('请输入对标项目总资金');
          return
        }
        if (!this.ruleFormE.safe_factor) {
          this.$message.error('请输入安全系数');
          return
        }
        serveApi.mortgage_assets(this.ruleFormE).then(res => {
          if (res.data) {
            this.ruleForm1.benchmark = res.data.mortgage_assets;
            this.$message.success('运算成功');
          } else {
            this.$message.error(res.message);
          }
        });
      },



    }
  }
</script>

<style scoped lang="scss">
  /* 表单的lable */
  .el-form--label-top .el-form-item__label {
    float: none;
    display: inline-block;
    text-align: left;
    padding: 0;


    font-size: 14px;
    font-family: MicrosoftYaHei;
    color: #3B3734;
  }
</style>
<style scoped lang="scss">
  .view-box {
    background-color: #ece9e7;
  }

  h6 {
    height: 73px;
    font-size: 36px;
    font-family: MicrosoftYaHeiSemibold;
    color: #3B3734;
    line-height: 48px;
    letter-spacing: 1px;
    position: relative;

    &::after {
      content: '';
      width: 66px;
      position: absolute;
      border-bottom: 2px solid #007AFF;
      bottom: 0px;
      margin-top: 25px;
    }
  }

  .form-box {
    width: 95%;
    // height: 800px;
    background: #FFFFFF;
    box-shadow: 0px 0px 10px 0px rgba(178, 178, 178, 0.2);
    border-radius: 4px;
    margin-top: 47px;
    padding: 24px;
    margin-bottom: 50px;


  }

  .upload-demo {
    width: 50%;

    button {
      width: 50%;
    }

    .el-upload {

      width: 100%;

      .el-button {
        height: 50px;
        width: 100%;
        background: transparent;
        color: rgba(43, 139, 195, 1);
        font-size: 14px;
        border: 1px dashed #dddddd;
      }
    }

    .el-upload__tip {
      line-height: 20px;
      color: rgba(153, 153, 153, 1);
      font-size: 13px;

      a {
        color: rgba(43, 139, 195, 1);
        cursor: pointer;
      }
    }
  }
</style>
